//
//  D1TABTableAnimated01ViewCell.m
//  STBasicsApp
//
//  Created by jerry on 2019/5/3.
//  Copyright © 2019 jerry. All rights reserved.
//

#import "D1TABTableAnimated01ViewCell.h"
#import "D1CommonModel.h"

@interface D1TABTableAnimated01ViewCell() {
    UIImageView *gameImg;
    UILabel     *titleLab;
}

@end

@implementation D1TABTableAnimated01ViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initUI];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    // 获取对应组件文本大小
    CGSize titleSize = [self getLabelSizeBy:titleLab andContent:titleLab.text andMaxLabelWidth:OG_Main_Screen_Width-(self.frame.size.height-20)*1.5-15-15-10];
   
    // 布局
    gameImg.frame = CGRectMake(15, 10, (self.frame.size.height-20)*1.5, (self.frame.size.height-20));
    gameImg.layer.cornerRadius = 5;
    
    titleLab.frame = CGRectMake(CGRectGetMaxX(gameImg.frame)+15, 10, titleSize.width, titleSize.height);
}

#pragma mark - Public Methods

- (void)initWithData:(D1CommonModel *)model {
    titleLab.text = [NSString stringWithFormat:@"测试数据测试数据测试数据测试数据测试数据测试数据测试数据%@～",model.gameId];
    [gameImg setImage:[UIImage imageNamed:@"st_pic_table_item"]];
}

#pragma mark - Initize Methods

- (void)initUI {
    
    {
        UIImageView *iv = [[UIImageView alloc] init];
        iv.contentMode = UIViewContentModeScaleAspectFill;
        iv.layer.masksToBounds = YES;
        
        gameImg = iv;
        [self.contentView addSubview:iv];
    }
    
    {
        UILabel *lab = [[UILabel alloc]init];
        [lab setFont:kFont(15)];
        lab.numberOfLines = 3;
        [lab setTextColor:[UIColor blackColor]];
        titleLab = lab;
        [self.contentView addSubview:lab];
    }
}

- (CGSize) getLabelSizeBy:(UILabel *) label andContent:(NSString *) content andMaxLabelWidth:(CGFloat) maxWidth {
    NSString * text = label.text;
    if(!(content && ! [content isEqualToString:@""])) {
        return CGSizeZero;
    }
    [label setText:content];
    CGSize resultSize = [label sizeThatFits:CGSizeMake(maxWidth, MAXFLOAT)];
    [label setText:text];
    return resultSize;
}

@end
